<?php
/**
 * @Auth: wonli <wonli@live.com>
 * BaseView.php
 */

class BaseView extends CoreView
{
    function __construct()
    {
        parent::__construct();
        $skin = $this->config->get('sys', 'default_tpl');

        if (isset($_COOKIE['skin']) && $_COOKIE['skin'] != 'default')
        {
            $skin_default_layer = APP_PATH_DIR.DS.APP_NAME."/templates/".$_COOKIE['skin'];
            if (is_dir($skin_default_layer))
            {
                $skin = $_COOKIE['skin'];
            }
        }

        $this->config->set('sys', array('default_tpl_dir'=>$skin));
    }

    function page($page, $tpl='page')
    {
        @list($controller, $params) = $page['link'];
        if(empty($params)) $params = array();

        $_dot = isset($page['dot']) ? $page["dot"] : $this->urlconfig['dot'];
        include $this->tpl("page/{$tpl}");
    }

    function copyRight()
    {
        ?>
        <span>Ideaa 2012 Powered by <a href="http://git.oschina.net/ideaa/crossphp">CrossPHP</a></span>
        <?php
    }

    function setSkin()
    {
        ?>
        <script type="text/javascript" src="<?php echo $this->res("lib/qTip2/jquery.qtip.min.js") ?>"></script>
        <link rel="stylesheet" type="text/css" href="<?php echo $this->res("lib/qTip2/jquery.qtip.min.css") ?>" media="all" />
        <div style="position: relative">
            <a id="changeSkin" href="javascript:void(0)">换肤</a>

            <div id="setSkin" style="width:200px;height:30px;display:none;">
                <a class="pure-button" href="<?php echo $this->link("main:setSkin", array('skin_name'=>'default')) ?>">default</a>
                <a class="pure-button" href="<?php echo $this->link("main:setSkin", array('skin_name'=>'nsf')) ?>">nsf</a>
                <a class="pure-button" href="<?php echo $this->link("main:setSkin", array('skin_name'=>'pure')) ?>">pure</a>
            </div>
        </div>
        <script>
            $("#changeSkin").qtip({
                content: {
                    text: $("#setSkin"),// Use the "div" element next to this for the content
                    prerender: true
                },
                position: {
                    target: 'mouse', // Position it where the click was...
                    adjust: { mouse: false } // ...but don't follow the mouse
                },
                show: 'mousedown',
            });
        </script>
        <?php
    }
}
